<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'setTimeout.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>

	<body>
		This is my setTimeout page.
		<br>

		<input type="button" value="setTimeout 测试" onclick="show();" />

		<script type="text/javascript">
    	function show(){
    		setTimeout(function (){alert("五秒以后看见我");},5000);
    		alert("点击以后，立刻见我");
    	}
    </script>

	<!-- 前台通用Jquery引用 -->
	<script type="text/javascript" src="<%=path%>/js/jquery/jquery-1.4.2.js"></script>
	
	<script type="text/javascript">
    
    function Sleeper()
	{
	  var self = this;
	  var FUNC = 0;
	  var TIME = 1;
	 
	  self.step    = 0;
	  self.actions = [];
	 
	  self.push = function(func, time) {
	    if (typeof(time) == 'undefined') {
	      time = 0;
	    }
	    self.actions.push([func, time]);
	    return self;
	  }
	  self.run_next = function() {
	    if (self.step < self.actions.length) {
	      var action = self.actions[self.step];
	      func = action[FUNC];
	      time = action[TIME];
	      if (typeof(func) == 'function') {
	        func();
	      } else {
	        eval(func);
	      }
	      ++self.step;
	      setTimeout(self.run_next, time);
	      $("body").append("<br>"+"run_next is end....."+self.step);
	    }
	  }
	  self.run = function() {
	    self.run_next();
	    $("body").append("<br>run is end.....");
	  }
	  return self;
	}
	
	var s = new Sleeper()
	var a;
	var b;
	s.push(function() {$("body").append("<br>11");}, 1000)
	.push(function() {$("body").append("<br>22");}, 50)
	.push(function() {$("body").append("<br>33");}, 2000)
	.push(function() {$("body").append("<br>44.....");} )
	.run()
	
	$("body").append("<br>body is end.....");
    </script>

	</body>
</html>
